﻿namespace Fiddler
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class frmAlert : Form
    {
        private Button btnNo;
        private Button btnOk;
        private Button btnYes;
        private Container components;
        private Label lblHint;
        private PictureBox pbImage;
        private RichTextBox txtMessage;

        public frmAlert()
        {
            this.InitializeComponent();
            this.Font = new Font(this.Font.FontFamily, CONFIG.flFontSize);
            base.AcceptButton = base.CancelButton = this.btnOk;
        }

        public frmAlert(string sTitle, string sMessage, string sHint) : this()
        {
            this.Text = " " + sTitle;
            this.txtMessage.Text = sMessage;
            this.lblHint.Text = sHint;
        }

        public frmAlert(string sTitle, string sMessage, string sHint, MessageBoxButtons mbButtons, MessageBoxDefaultButton mbDefault) : this(sTitle, sMessage, sHint)
        {
            if (mbButtons == MessageBoxButtons.YesNo)
            {
                this.lblHint.Width = 260;
                this.lblHint.ForeColor = Color.FromKnownColor(KnownColor.WindowText);
                this.lblHint.TextAlign = ContentAlignment.MiddleRight;
                this.lblHint.Font = new Font(this.lblHint.Font, FontStyle.Bold);
                this.btnOk.Visible = false;
                this.btnNo.Visible = true;
                this.btnYes.Visible = true;
                base.CancelButton = this.btnNo;
                if (mbDefault == MessageBoxDefaultButton.Button1)
                {
                    base.AcceptButton = this.btnYes;
                    base.ActiveControl = this.btnYes;
                }
                else
                {
                    base.AcceptButton = this.btnNo;
                    base.ActiveControl = this.btnNo;
                }
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void frmAlert_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.C))
            {
                e.SuppressKeyPress = e.Handled = true;
                if (this.txtMessage.SelectionLength < 1)
                {
                    this.txtMessage.SelectAll();
                }
                this.txtMessage.Copy();
            }
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(frmAlert));
            this.pbImage = new PictureBox();
            this.btnOk = new Button();
            this.txtMessage = new RichTextBox();
            this.lblHint = new Label();
            this.btnYes = new Button();
            this.btnNo = new Button();
            ((ISupportInitialize) this.pbImage).BeginInit();
            base.SuspendLayout();
            this.pbImage.Image = (Image) manager.GetObject("pbImage.Image");
            this.pbImage.Location = new Point(8, 8);
            this.pbImage.Name = "pbImage";
            this.pbImage.Size = new Size(0x20, 0x20);
            this.pbImage.SizeMode = PictureBoxSizeMode.CenterImage;
            this.pbImage.TabIndex = 0;
            this.pbImage.TabStop = false;
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnOk.DialogResult = DialogResult.OK;
            this.btnOk.Location = new Point(360, 0x88);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x4b, 0x17);
            this.btnOk.TabIndex = 2;
            this.btnOk.Text = "OK";
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.txtMessage.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.txtMessage.BackColor = SystemColors.Control;
            this.txtMessage.BorderStyle = BorderStyle.None;
            this.txtMessage.Location = new Point(0x30, 8);
            this.txtMessage.Name = "txtMessage";
            this.txtMessage.ReadOnly = true;
            this.txtMessage.Size = new Size(0x180, 120);
            this.txtMessage.TabIndex = 3;
            this.txtMessage.Text = manager.GetString("txtMessage.Text");
            this.txtMessage.LinkClicked += new LinkClickedEventHandler(this.txtMessage_LinkClicked);
            this.lblHint.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
            this.lblHint.ForeColor = SystemColors.ControlDarkDark;
            this.lblHint.Location = new Point(8, 140);
            this.lblHint.Name = "lblHint";
            this.lblHint.Size = new Size(0x160, 0x10);
            this.lblHint.TabIndex = 4;
            this.lblHint.Text = "WWMgqWWMgqWMgqWMgqWWMgqWMgqWWMgqWMgqWWMgq";
            this.lblHint.TextAlign = ContentAlignment.MiddleLeft;
            this.btnYes.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnYes.DialogResult = DialogResult.Yes;
            this.btnYes.Location = new Point(280, 0x88);
            this.btnYes.Name = "btnYes";
            this.btnYes.Size = new Size(0x4b, 0x17);
            this.btnYes.TabIndex = 5;
            this.btnYes.Text = "&Yes";
            this.btnYes.Visible = false;
            this.btnNo.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
           // this.btnNo.DialogResult = DialogResult.No;
            this.btnNo.Location = new Point(360, 0x88);
            this.btnNo.Name = "btnNo";
            this.btnNo.Size = new Size(0x4b, 0x17);
            this.btnNo.TabIndex = 6;
            this.btnNo.Text = "&No";
            this.btnNo.Visible = false;
            this.AutoScaleBaseSize = new Size(5, 14);
            base.ClientSize = new Size(440, 0xa6);
            base.Controls.Add(this.btnNo);
            base.Controls.Add(this.btnYes);
            base.Controls.Add(this.lblHint);
            base.Controls.Add(this.txtMessage);
            base.Controls.Add(this.btnOk);
            base.Controls.Add(this.pbImage);
            this.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
           // base.FormBorderStyle = FormBorderStyle.SizableToolWindow;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.KeyPreview = true;
            base.Name = "frmAlert";
          //  base.SizeGripStyle = SizeGripStyle.Hide;
            base.StartPosition = FormStartPosition.Manual;
            this.Text = " Fiddler Alert";
            base.KeyDown += new KeyEventHandler(this.frmAlert_KeyDown);
            ((ISupportInitialize) this.pbImage).EndInit();
            base.ResumeLayout(false);
        }

        private void txtMessage_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            Utilities.LaunchHyperlink(e.LinkText);
        }
    }
}

